/*
 * @Project Name: spring-boot
 * @File Name: UserService
 * @Package Name: com.hhly.spring.boot.cache
 * @Date: 2017/12/13 17:52
 * @Creator: linshixing-1199
 * @line------------------------------
 * @修改人:
 * @修改时间:
 * @修改内容:
 */

package com.sm.shoplook.service.base.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.sm.shoplook.constant.ResultMessage;
import com.sm.shoplook.dao.mapper.base.MaterialCategoryMapper;
import com.sm.shoplook.domain.base.MaterialCategory;
import com.sm.shoplook.service.base.MaterialCategoryService;
import com.sm.shoplook.vo.base.ApiException;
import com.sm.shoplook.vo.base.ApiResult;
import com.sm.shoplook.vo.base.BaseSearchVo;

/**
 * @author chenpy-1072
 * @desc 基础素材管理
 * @date 2017/12/13 17:52
 * @see
 */
@Service
public class MaterialCategoryServiceImpl implements MaterialCategoryService {

	private static final Logger LOGGER = LoggerFactory.getLogger(MaterialCategoryServiceImpl.class);
	@Autowired
	private MaterialCategoryMapper materialCategoryMapper;

	@Override
	public ApiResult<PageInfo<MaterialCategory>> selectMaterialCategorysPage(BaseSearchVo baseSearchVo) {
		PageHelper.startPage(baseSearchVo.getOffset(), baseSearchVo.getPageSize());
		MaterialCategory materialCategory = new MaterialCategory();
		materialCategory.setStatus(1);
		List<MaterialCategory> materialCategories = materialCategoryMapper.select(materialCategory);
		return new ApiResult<>(ResultMessage.RESULT_SUCCESS_1, new PageInfo<>(materialCategories));
	}

	@Override
	public ApiResult deleteMaterialCategorys(String[] idList) throws ApiException {
		int i = materialCategoryMapper.deleteMaterialCategorys(idList);
		if (i < 1) {
			throw new ApiException();
		}
		return new ApiResult(ResultMessage.RESULT_SUCCESS_1);
	}

	@Override
	public ApiResult saveMaterialCategory(MaterialCategory materialCategory) throws ApiException {
		int i;
		if (materialCategory.getId() == null) {
			i = materialCategoryMapper.insertSelective(materialCategory);
		} else {
			i = materialCategoryMapper.updateByPrimaryKeySelective(materialCategory);
		}
		if (i < 1) {
			throw new ApiException();
		}
		return new ApiResult(ResultMessage.RESULT_SUCCESS_1);
	}

	@Override
	public ApiResult<List<MaterialCategory>> selectAllMaterialCategorys() {
		MaterialCategory materialCategory = new MaterialCategory();
		materialCategory.setStatus(1);
		return new ApiResult<>(ResultMessage.RESULT_SUCCESS_1, materialCategoryMapper.select(materialCategory));
	}

	@Override
	public ApiResult<MaterialCategory> selectMaterialCategoryById(Integer id) {
		return new ApiResult<>(ResultMessage.RESULT_SUCCESS_1, materialCategoryMapper.selectByPrimaryKey(id));
	}
}
